<template>
  <el-button v-if="!hidden"
             :type="type"
             :size="size"
             :plain="plain"
             :round="round"
             :circle="circle"
             :icon="icon"
             :disabled="disabled"
             :link="link"
             :loading="loading"
             :class="['yv-button', calcClass]"
             :style="calcStyle"
             @click="_onClick">{{ text }}
  </el-button>
</template>
<script>
import _ from 'lodash'
import ButtonMeta from './ButtonMeta'
import WebVjsonMix from "../WebVjsonMix"
import {renderIcon} from "../webutils"

export default {
  mixins: [WebVjsonMix],
  emits: [],
  expose: [],
  data() {
    const propsWithDefaults = ButtonMeta.loadVjsonWithDefault(this)

    return {
      text: propsWithDefaults.text,
      type: propsWithDefaults.type,
      size: propsWithDefaults.size,
      plain: propsWithDefaults.plain,
      round: propsWithDefaults.round,
      circle: propsWithDefaults.circle,
      disabled: propsWithDefaults.disabled,
      link: propsWithDefaults.link,
      loading: propsWithDefaults.loading,
      iconCls: propsWithDefaults.iconCls,
    }
  },
  computed: {
    icon() {
      return renderIcon(this.iconCls)
    },
  },
  methods: {
    _onClick(evt) {
      system.globalLoadingButtonInstance = this

      // this.runEvent('click', ...arguments)
      ButtonMeta.vjsonEmit.click(this, evt)

      system.globalLoadingButtonInstance = null
    },

    performClick(evt) {
      this._onClick(evt)
    }
  }
}
</script>